// Program: test
// Description: Program which can be edited to perform manual tests of features.
//

//
// main.cc -- Defines the main startup routine, and runloop.
//

#include <stdlib.h>
#include <jimix/FileDescriptor.h>
#include <jimix/File.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <jimix/Globals.h>
#include <sys/termios.h>
#include <signal.h>
extern "C" int _kill(pid_t pid, int sig);
void sighand(int sig)
{
  printf("Signal recieved: %d\n", sig);
}

extern int errno;
int main(char argc, char **argv)
{
  signal(10, &sighand);
  raise(10);
  
  FILE *stream3 = fopen ("/dev/ttyS1", "w");
  if (stream3)
  {
    fprintf(stream3, "You are a serial port!\n");
    fclose(stream3);
  }
  else
  {
    printf("Error opening stream.\n");
  }
  
  int pid;
  if ( (pid = fork()) == 0 )
  {
    printf("I am a child, and have a pid of %d!\n", getpid());
    char *a = NULL;
    char *b = NULL;
    return 16;
  }
  else
  {
    printf("I am a parent, have a pid of %d, and my child is %d!\n", getpid(), pid);
    int ret;
    int ret2 = waitpid(-1, &ret, 0);
    printf("Child exited with status %d, %d, errno is %d\n", ret, ret2, errno);
  }
  return 0;
}
